/**
 * @param {string} s  
 * @return {number}
 */

var secondsToRemoveOccurrences = function (s) {

  /**
   * 
   *  solution 1
   * 
   *   while(s.indexOf('01')!=-1){
    count++
    s = s.replace(/01/g,'10')
  }
   */
  
  /**
   * solution 2
   */
  let count = 0,prefix=0
  for(const c of s){
    if(c ==='0'){
      prefix++
    }else if(prefix){
      count =Math.max(count+1,prefix)
    }
  }


  return count
};

secondsToRemoveOccurrences("0110101")

